var app = sm("do_App");
var page = sm("do_Page");
//定义一个DateTimePicker对象
var do_DateTimePicker = sm("do_DateTimePicker")

// UI
var headerAout = ui("headerAout");
//andriod返回键
page.on("back", function() {
	app.closePage();
});
/* 头部 */
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
	app.closePage()
});
ui(addheader+".labelTitle").text = "订单搜索";

// 定义变量
var labelStartTime=ui("labelStartTime");
var aLayoutStartTime=ui("aLayoutStartTime");
var labelEndTime=ui("labelEndTime");
var aLayoutEndTime=ui("aLayoutEndTime");
var do_Button_search=ui("do_Button_search");

do_Button_search.on("touch",function(){
	app.closePage({searchBTime:searchBTime,searchETime:searchETime});
})

//定义时间
var myDate=new Date(2015,01,01);
var date0 = myDate.getTime();

var myDate=new Date(2050,01,01);
var dateMax = myDate.getTime();

var searchBTime,searchETime;
//选择日期方式，最大日期为2050年最小日期为2001年，预设日期为当前时间，设置按钮文字
aLayoutStartTime.on("touch",function(){
	do_DateTimePicker.show({type:1, data:date0, minDate:date0,maxDate:dateMax, title:"日期选择", buttons:["取消","确定"]}, function(data, e){
        if(data.flag==1){
        	searchBTime=parseInt(data.time,10);
        	labelStartTime.text=timeFormat(searchBTime);
        }
    });
})
//选择日期方式，最大日期为2050年最小日期为2001年，预设日期为当前时间，设置按钮文字
aLayoutEndTime.on("touch",function(){
	do_DateTimePicker.show({type:1, data:date0,minDate:date0,maxDate:dateMax, title:"日期选择", buttons:["取消","确定"]}, function(data, e){
        if(data.flag==1){
        	searchETime=parseInt(data.time,10);
        	labelEndTime.text=timeFormat(searchETime);
        }
    });
})

function timeFormat(time){
	var svDate = new Date(time);//要格式化的时间
	return svDate.getFullYear()+"/"+(svDate.getMonth()+1)+"/"+svDate.getDate();
}
